<link rel="stylesheet" href="/styles/flexigrid.css" />
<link rel="stylesheet" href="/styles/thickbox.css" />
<script type="text/javascript" src="/scripts/jquery-1.3.2.js"></script>
<script type="text/javascript" src="/scripts/flexigrid.js"></script>
<script type="text/javascript" src="/scripts/thickbox.js"></script>

<script type="text/javascript">
//<![CDATA[
$(document).ready(function(){

	$("#flex1").flexigrid
			(
			{
			url: '/admin-mvc/user/index/list/',
			dataType: 'json',
			colModel : [
			    {display: 'User Id', name : 'user_id', width : 80, sortable : true, align: 'left'},			    
			    {display: 'First Name', name : 'first_name', width : 150, sortable : true, align: 'left'},
				{display: 'Last Name', name : 'last_name', width : 150, sortable : true, align: 'left'},
				{display: 'Email', name : 'email', width : 200, sortable : true, align: 'left'},
				{display: 'Age', name : 'age', width : 50, sortable : true, align: 'left'},
				{display: 'Institution', name : 'institution', width : 160, sortable : true, align: 'left'},
				{display: 'Year', name : 'year', width : 100, sortable : true, align: 'left'},		
				{display: 'Major', name : 'major', width : 150, sortable : true, align: 'left'},
				{display: 'Zip Code', name : 'zip', width : 150, sortable : true, align: 'left'},
				{display: 'Created Date', name : 'created_date', width : 150, sortable : true, align: 'left'},
				{display: 'Modified Date', name : 'modified_date', width : 150, sortable : true, align: 'left'},
				{display: 'Status', name : 'active', width : 150, sortable : true, align: 'left'}
				],
			buttons : [
				{name: 'View User Activity', bclass: 'add', onpress : gridAction},
				{separator: true},
				{name: 'View All Activity', bclass: 'add', onpress : gridAction},
				{separator: true},
				{name: 'Export User Content', bclass: 'add', onpress : exportTo},
				{separator: true},
				{name: 'Export All Users Content', bclass: 'add', onpress : exportAll},												
			],
			searchitems : [
				{display: 'First Name', name : 'first_name', isdefault:false},
				{display: 'Last Name', name : 'last_name', isdefault:false},
				{display: 'Email', name : 'email', isdefault:false}		
				],
			sortname: "user_id",
			sortorder: "desc",
			usepager: true,		
			title: "Report",	
			useRp: true,
			rp: 10,
			showTableToggleBtn: false,
			width: 980,
			height: 320
			}
			);   
	
});
function exportTo(com,grid)
{
	if (com=='Export User Content'){
		if($('.trSelected',grid).length==1){
		var items = $('.trSelected',grid);
		var itemlist ='';
		for(i=0;i<items.length;i++){
			itemlist+= items[i].id.substr(3);
			}
        	window.location = '/report/user_report.php?id='+itemlist;
		} else if($('.trSelected',grid).length==0) {
			alert('Please select at least 1 User');
		} else {
			alert('Please select only 1 User');
		} 
	}  
}
function exportAll(com,grid)
{
window.location = '/report/user_report.php';
}
function sortAlpha(com)
			{ 
			
			jQuery('#flex1').flexOptions({newp:1, params:[{name:'letter_pressed', value: com},{name:'qtype',value:$('select[name=qtype]').val()}]});
			jQuery("#flex1").flexReload(); 
			}
function gridAction(com,grid)
{
	var totval = $('.trSelected',grid).length;
	 if (com=='View All Activity'){
	 	tb_show('All Activities','/admin-mvc/user/index/view-all-activity/?height=200&width=450',null);
	 }
	 else if (com=='View User Activity'){
		if($('.trSelected',grid).length>0){
	   		if($('.trSelected',grid).length == 1){
			var items = $('.trSelected',grid);
            	var itemlist ='';
        		itemlist = items[0].id.substr(3);
				/*if(confirm('Activate ' + $('.trSelected',grid).length + ' User(s)?')){
            	var items = $('.trSelected',grid);
            	var itemlist ='';
        		for(i=0;i<items.length;i++){
					itemlist+= items[i].id.substr(3)+",";
				}
				$.ajax({
					type: "POST",
				   	dataType: "json",
				   	url: "/admin-mvc/user/index/activate",
				   	data: "items="+itemlist,
				   	success: function(data){
				   		alert(totval + " User(s) Activated");
				   		$("#flex1").flexReload();
			   	    }
				});
			}*/
		
			tb_show('User Activity','/admin-mvc/user/index/view-activity/'+itemlist+'?height=350&width=600',null);
			}
			else
			{
				alert('Please select only 1 User');
			}
		} else {
			alert('Please select at least 1 User');
		} 
	} else if (com=='De-Activate'){
		if($('.trSelected',grid).length>0){
	   		if(confirm('De-Activate ' + $('.trSelected',grid).length + ' User(s)?')){
            	var items = $('.trSelected',grid);
            	var itemlist ='';
        		for(i=0;i<items.length;i++){
					itemlist+= items[i].id.substr(3)+",";
				}
				$.ajax({
					type: "POST",
				   	dataType: "json",
				   	url: "/admin-mvc/user/index/deactivate",
				   	data: "items="+itemlist,
				   	success: function(data){
				   		alert(totval + " User(s) De-Activated");
				   		$("#flex1").flexReload();
			   	    }
				});
			}
		} else {
			alert('Please select at least 1 User');
		} 
	}
	
	else if (com=='Approve'){
		if($('.trSelected',grid).length>0){
	   		if(confirm('Approved ' + $('.trSelected',grid).length + ' User(s)?')){
            	var items = $('.trSelected',grid);
            	var itemlist ='';
        		for(i=0;i<items.length;i++){
					itemlist+= items[i].id.substr(3)+",";
				}
				$.ajax({
					type: "POST",
				   	dataType: "json",
				   	url: "/admin-mvc/user/index/approve",
				   	data: "items="+itemlist,
				   	success: function(data){
				   		alert(totval + " User(s) Approved");
				   		$("#flex1").flexReload();
			   	    }
				});
			}
		} else {
			alert('Please select at least 1 User');
		} 
	} else if (com=='Disapprove'){
		if($('.trSelected',grid).length>0){
	   		if(confirm('Disapproved ' + $('.trSelected',grid).length + ' User(s)?')){
            	var items = $('.trSelected',grid);
            	var itemlist ='';
        		for(i=0;i<items.length;i++){
					itemlist+= items[i].id.substr(3)+",";
				}
				$.ajax({
					type: "POST",
				   	dataType: "json",
				   	url: "/admin-mvc/user/index/disapprove",
				   	data: "items="+itemlist,
				   	success: function(data){
				   		alert(totval + " User(s) Disapproved");
				   		$("#flex1").flexReload();
			   	    }
				});
			}
		} else {
			alert('Please select at least 1 User');
		} 
	}
	
	 else if (com=='Delete'){
		if($('.trSelected',grid).length>0){
	   		if(confirm('Delete ' + $('.trSelected',grid).length + ' User(s)?')){
            	var items = $('.trSelected',grid);
            	var itemlist ='';
        		for(i=0;i<items.length;i++){
					itemlist+= items[i].id.substr(3)+",";
				}
				$.ajax({
					type: "POST",
				   	dataType: "json",
				   	url: "/admin-mvc/user/index/delete",
				   	data: "items="+itemlist,
				   	success: function(data){
				   		alert(totval + " User(s) Deleted");
				   		$("#flex1").flexReload();
			   	    }
				});
			}
		} else {
			alert('Please select at least 1 User');
		} 
	}
	
	 else if (com=='Add User'){
	 
		AddContent('/register/','Add User');
	}else if(com=='Edit User'){
	       if($('.trSelected',grid).length>0 && $('.trSelected',grid).length<=1 ){
	   		
            	var items = $('.trSelected',grid);
            	var itemlist ='';
        		itemlist+= items[0].id.substr(3);
				
				AddContent('/admin-mvc/user/index/edit/'+itemlist+'?height=100&width=550','Edit User');
				
		} else if($('.trSelected',grid).length==0){
			alert('Please select an User');
		} else {
			alert('Please select Only 1 User');
		}
			
	}
	else if(com=='Contact Users')
	{  if($('.trSelected',grid).length>0 ){
	   		
            	var items = $('.trSelected',grid);
            	var itemlist ='';
        		for(i=0;i<items.length;i++){
					itemlist+= items[i].id.substr(3)+",";
				}
			$('#userId').val(itemlist);
			document.userFrm.action = '/admin-mvc/user/index/contact-users/';
			document.userFrm.submit();
			//window.location = '/admin-mvc/user/index/contact-users/'+itemlist;
			} else {
			alert('Please select at least 1 User');
		} 
	}
	else if(com=='Contact All Users')
	{
			$('#userId').val('0');
			document.userFrm.action = '/admin-mvc/user/index/contact-users/';
			document.userFrm.submit();
			//window.location = '/admin-mvc/user/index/contact-users/0';
	}
}
function AddContent(linkUrl,title)
{
	
	//tb_show(title,linkUrl,null);
	window.location = linkUrl;
	
}

//]]>
</script>
<form id="userFrm" name="userFrm"  method="post">
<input type="hidden" name="userId"  value="" id="userId"/>
</form>
<div id="content_body">

	<div class="clear"></div><br/>
<table id="flex1" style="display:none;"></table><br/>
<div class="clear"></div>

</div>
<div class="clear"></div>

